import {request} from "vendor/utils/T";
import {toApi} from "@/service/proxyApi";
import {RequestDataType, RespDataType} from "./apiType";

export * from "./apiType";

const { get, postJSON, del, put } = request;

/**
 * 获取账户分页列表
 */
export const getAccountPageList = (params: { page: number, pageSize: number }) => {
    return get<RespDataType.AccountPageList>(toApi("system/account/list"), params);
}

/**
 * 创建账户
 */
export const createAccount = (params: RequestDataType.CreateAccountItem) => {
    return postJSON(toApi("system/account"), params);
}

/**
 * 获取账户信息
 */
export const getAccountInfo = (accountId: string) => {
    return get<RespDataType.AccountItem>(toApi("system/account"), {accountId});
}

/**
 * 更新账户信息
 */
export const updateAccount = (accountId: string, params: Partial<RequestDataType.UpdateAccountItem>) => {
    return put(toApi(`system/account?accountId=${accountId}`), params);
}

/**
 * 删除账户信息
 */
export const deleteAccount = (accountIds: string[]) => {
    return del(toApi(`system/account`), {sIds: accountIds});
}

/**
 * 启用账户
 */
export const startAccount = (accountId: string) => {
    return put(toApi(`system/account/start?accountId=${accountId}`))
}

/**
 * 停用账户
 */
export const stopAccount = (accountId: string) => {
    return put(toApi(`system/account/stop?accountId=${accountId}`))
}

/**
 * 初始化账户的管理员
 */
export const initAdminOfAccount = (accountId: string, params: RequestDataType.InitAdminUserParams) => {
    return put(toApi(`system/account/initAdmin?accountId=${accountId}`), params);
}


//------------------------------授权秘钥相关的接口------------------------

/**
 * 创建授权秘钥
 */
export const createAuthSecret = (params: RequestDataType.SaveAuthSecretParams) => {
    return postJSON(toApi(`external/auth/config`), params);
}

/**
 * 更新授权秘钥
 */
export const updateAuthSecret = (accountId: string, params: Partial<RequestDataType.SaveAuthSecretParams>) => {
    return put(toApi(`external/auth/config?accountId=${accountId}`), params);
}


/**
 * 获取授权秘钥信息
 */
export const getAuthSecretInfo = (accountId: string) => {
    return get<RespDataType.AuthSecretInfo>(toApi(`external/auth/config`), {accountId});
}

//------------------------------报告分组相关的接口------------------------

/**
 * 获取所有的报告分组列表
 */
export const getAllReportGroupList = () => {
    return get<RespDataType.ReportGroupList>(toApi(`report/manager/panel/list`));
}


/**
 * 绑定报告分组到account
 * @param accountId
 * @param sIds 报告分组ID列表
 */
export const bindReportGroupToAccount = (accountId: string, sIds: string[]) =>{
    return postJSON(toApi(`report/manager/panel?accountId=${accountId}`), {sIds})
}

/**
 * 获取已绑定的报告分组ID list
 */
export const getBindReportGroup = (accountId: string) => {
    return get<string[]>(toApi("report/manager/panel"), {accountId});
}

